menuList[5].onclick();

// 获取数据并渲染
current=1;
pageSize=10;
let result;
let searchContent = -1;
let flagData=1;//判断当前分页数据是那些类型 1、所有数据 2、搜索结果
async function fun(flagOptions){
    if(flagData==1){
        result = await getData(current,pageSize);
        // 分页
        console.log(result);
        counts = result.page.pageSizeTotal;
        pages = result.page.pageNoTotal;
        pageFun({
            current:current,
            pages:pages,
            counts:counts,
            flagOptions:flagOptions,
            pageSize:pageSize
        })

        // 不分页

    }else if(flagData==2){
        searchByUsername();
    }
}
fun(0);
function getData(current,pageSize){
    let findByBrowse = document.getElementById("findByBrowse");
    console.log(findByBrowse);
    return new Promise((resolve, reject) => {
        axios({
            url:'/admin/users/findByBrowse',
            method:'GET',
            params:{
                page:current,
                size:pageSize,
                userId:findByBrowse.getAttribute("name")
                }
            })
            .then(data => {
                console.warn(data.data);
                decorateFun(data)
                resolve(data.data);
            })
            .catch(err => {
                console.log(err);
            })
    });
   
}

// 搜索通过商品名
let searchInput = cl("searchInput");
function searchByUsername(){
    let findByBrowse = document.getElementById("findByBrowse");
    if(searchContent != searchInput.value){
        page=1;
        pageSize=10;
        current=1;
    } 
    console.warn(searchContent==searchInput.value);
    axios({
        url: '/admin/users/findSuchInBrowse',
        method: 'GET',
        params:{
            goodsName:searchInput.value,
            page: current,
            size: pageSize,
            userId:findByBrowse.getAttribute("name")
            }
        })
        .then(data => {
            if(data.data.code==20001){
                explain({
                    code:2,
                    msg:"抱歉未找到",
                    time:3000
                })
            }else{
                searchContent = searchInput.value
                flagData=2;
                result = data.data.data;
                counts = result.totalCounts;
                pages = result.totalPage
                console.log(result);
                decorateFun(data)
                pageFun({
                    current:current,
                    pages:result.totalPage,
                    counts:result.totalCounts,
                    pageSize:result.size
                })
            }
        })
        .catch(err => {
            console.log(err);
        })
}

// 渲染页面
function decorateFun(data){
    let tbodyMenu = cl("tbodyMenu");
    let dataNums = cl("dataNums");
    let pageMessage = cl("pageMessage");
    let end;
    // 分页
    console.log(data.data.data);
    // if(current==1){
    //     end=data.data.data.list.length;
    // }else{
    //     end =parseInt(current-1)*parseInt(data.data.data.size)+parseInt(data.data.data.list.length);
    // }
    // dataNums.innerHTML = data.data.data.list.length;
    pageMessage.innerHTML = `第${(current-1)*data.data.data.size+1}到${end}条记录，共${data.data.data.totalCounts}条`;
    console.warn(data.data.data);
    tbodyMenu.innerHTML ="";
    let i=0;
    for(let key in data.data.data){
        tbodyMenu.innerHTML += `
        <tr>
            <td >${i+1}</td>
            <td >${data.data.data[key].nickname}</td>
            <td >${data.data.data[key].goodsName?data.data.data[key].goodsName:'暂无'}</td>
            <td ><img src="${data.data.data[key].cover}" style="max-width:80px"/></td>
            <td>${data.data.data[key].goodsPrice?handlePrice(data.data.data[key].goodsPrice):'暂无'}</td>
            <td>${data.data.data[key].monthlySales?data.data.data[key].monthlySales:'暂无'}</td>
            <td>${data.data.data[key].browseTime}</td>
        </tr>
            `
            i++
        }
        dataNums.innerHTML = i;
        pageMessage.innerHTML = `该用户共${i}条浏览记录`;
}
// 输入框回车事件
function inputEnterFun(){
    console.log("a");
    if(event.keyCode == 13){
        searchByStorename()
    }
}

// 页面刷新
function reloadFun(){
    location.reload();
}

// 选择每页展示数量
function chooseSizeFun(){
    let selectNums = document.getElementById("selectNums");
    console.log(selectNums.children[1]);
    console.warn(selectNums.value);
    current = 1;
    pageSize =selectNums.value;
    fun(1);
    for(let i=0;i<selectNums.children.length;i++) {
        if(selectNums.children.length[i]==selectNums.value){
            selectNums.children.length[i].select="select";
        }
    }
}
// 关闭函数

// 关闭的操作
function closeUSerFun(){
    let covers = cl("covers");
    covers.style.display = 'none';
}




// 点击返回上一页
function returnFun(){
    window.history.back();  
}